/**
 * 
 */
package com.zhiteng.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiteng.entity.School;
import com.zhiteng.mapper.SchoolMapper;
import com.zhiteng.service.SchoolService;

/**  
* <p>Title: SchoolServiceImpl.java</p>  
* <p>Description: 学校Service</p>  
* @author dragon  
* @date 2018年11月7日  
* @version 1.0  
*/
@Service
public class SchoolServiceImpl implements SchoolService {
	@Autowired
	SchoolMapper schoolMapper;
	
	//	数据库中已存在就更新，不存在就插入
	@Override
	public int saveBatch(List<School> schoolList) {
		int count = 0;
		for (School school : schoolList) {
			//insertSelective插入数据，使用不为null的属性作为字段使用
			if(schoolMapper.existsWithPrimaryKey(school.getObjectid())) {	//	已存在，更新
				schoolMapper.updateByPrimaryKeySelective(school);
			}else {	//	不存在，插入
				schoolMapper.insertSelective(school);
			}
			++count;
		}
		return count;
	}

	@Override
	public List<School> getAllSchool() {
		return schoolMapper.selectAll();
	}

	@Override
	public School querySchoolById(String schoolId) {
		return schoolMapper.selectByPrimaryKey(schoolId);
	}

	@Override
	public School querySchoolBySchoolName(String school_name) {
		School school = new School();
		school.setName(school_name);
		return schoolMapper.selectOne(school);
	}
}
